public class ArrayCopy {
	public static void main(String[] args) {
		// Task 1: ary1 create and print
		int[] ary1 = {3, 5, 8, 9, 4};
		System.out.println("ary1: " + printArray(ary1));
		System.out.println("--------------------------");
		
		// Task 2: ary2=ary1 and modify
		int[] ary2 = ary1;
		ary2[3] = 11;
		System.out.println("ary1: " + printArray(ary1));
		System.out.println("ary2: " + printArray(ary2));
		System.out.println("--------------------------");
		
		// Task 3: ary2 = ary1.clone();
		ary1[3] = 9;
		ary2 = ary1.clone();
		ary2[3] = 11;
		System.out.println("ary1: " + printArray(ary1));
		System.out.println("ary2: " + printArray(ary2));
		System.out.println("--------------------------");

		// Task 4: ary2 = ary1.arraycopy()
		ary2 = new int[3];
		System.arraycopy(ary1, 2, ary2, 0, 3);
		System.out.println("ary2: " + printArray(ary2));
		System.out.println("--------------------------");
		
	}

	private static String printArray(int[] ary) {
		StringBuffer str = new StringBuffer();
		
		for (int i=0; i<ary.length; i++)
			str.append(ary[i] + " ");
		
		return str.toString();
	}
}
